from random import randint

def tony_sort(A:list):

    if len(A) <= 1:
        return

    border = A[randint(0, len(A)-1)]

    left = []
    middle = []
    right = []

    for digit in A:
        if digit < border:
            left.append(digit)
            
        elif digit == border:
            middle.append(digit)
            
        elif digit > border:
            right.append(digit)

        else:
            print('Error')
            raise ValueError
            
    tony_sort(left)
    tony_sort(right)

    index = 0
    for digit in left + middle + right:
        A[index] = digit
        index += 1

    return A

a = [randint(0, i) for i in range(20, 30)]
# a = [5, 4, 2, 1, 3]
print(a)
print(tony_sort(a))
